﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChanExt;

namespace C.Unite
{
    public class UploadHelper
    {
        /// <summary>
        /// 取得上传文件名
        /// </summary>
        /// <param name="fu"></param>
        /// <returns></returns>
        public static string GetUploadString(FileUpload fu, string hf)
        {
            string fileName = "";
            if (!hf.Contains("http://"))
            {
                if (fu.ShortFileName != "")
                {
                    fileName = fu.ShortFileName;
                    fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                    fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
                    if (fu.HasFile)
                    {
                        fu.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~/upload/" + fileName));
                    }
                    fileName = System.Configuration.ConfigurationManager.AppSettings["SavePicUrl"] + fileName;
                }
            }
            else
            {
                fileName = hf;
            }
            return fileName;
        }

        /// <summary>
        /// 取得上传文件名
        /// </summary>
        /// <param name="fu"></param>
        /// <returns></returns>
        public static string GetUpload(FileUpload fu, string hf)
        {
            string fileName = "";
            if (fu.ShortFileName != "")
            {
                fileName = fu.ShortFileName;
                fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
                if (fu.HasFile)
                {
                    fu.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~/upload/exceltemp/" + fileName));
                }
            }
            return "~/upload/exceltemp/" + fileName;
        }
    }
}